<template>
	<view class="container">
		<!-- 标题 -->
		<headTitle title="地址管理" :bottomline="true"></headTitle>
		<view class="new font28 color666" @click="addAddress('add')">新建地址</view>
		<view class="interval"></view>
		<view class="content flex-center" v-for="(item, index) in addressList" :key="index">
			<view class="left" @tap="checkAddress(item)">
				<view class="name font32 color333 fontb">
					{{ item.name }}
					<text class="tel font30">{{ item.phoneNumber | cipherTepl }}</text>
				</view>
				<view class="address font28 color999">
					收货地址：{{ item.province + item.city + item.region + item.detailAddress }}
				</view>
			</view>
			<view class="right">
				<view class="edit flex-center-center">
					<view class="default font26 colorfff" v-if="item.defaultStatus == 1">默认</view>
					<image src="/static/image/addedit.png" mode="" @tap="addAddress('edit', item)"></image>
				</view>
			</view>
		</view>
	</view>
</template>

<script>
import Api from '@/common/api'
import headTitle from '@/components/head-title.vue'
export default {
	data() {
		return {
			source: 0,
			addressList: [],
		};
	},
	async onLoad(option) {
		this.source = option.source
	},
	async onShow(){
		this.getListAddress()
	},
	methods: {
		async getListAddress(){
			let params = {};
			this.addressList = await Api.apiCall('get', Api.goods.listAddress, params);
		},
		//选择地址
		checkAddress(item) {
			if (this.source == 1) {
				//this.$api.prePage()获取上一页实例，在App.vue定义
				this.$api.prePage().addressData = item;
				this.$api.prePage().addressId = item.id;
				uni.navigateBack();
			}
		},
		addAddress(type, item) {
			uni.navigateTo({
				url: `/pages/address/addressManage?type=${type}&data=${JSON.stringify(item)}`
			});
		},
	},
	components:{
		headTitle
	}
};
</script>

<style lang="scss">
.new {
	position: fixed;
	top: 0;
	right: 30rpx;
	height: 88rpx;
	line-height: 88rpx;
	z-index: 10;
}
.interval {
	width: 100%;
	height: 16rpx;
	background-color: #f5f5f5;
}
.content {
	padding: 37rpx 0 35rpx 30rpx;
	border-bottom: 1rpx solid #EEE;
	.left {
		width: 590rpx;
		letter-spacing: 1rpx;
		.name {
			line-height: 48rpx;
			margin-bottom: 20rpx;
			.tel {
				margin-left: 40rpx;
			}
		}
		.address {
			line-height: 40rpx;
		}
	}
	.right {
		width: 130rpx;
		display: flex;
		justify-content: flex-end;
		.edit {
			width: 88rpx;
			height: 69rpx;
			position: relative;
			.default {
				position: absolute;
				top: -42rpx;
				left: -34rpx;
				width: 92rpx;
				height: 42rpx;
				line-height: 42rpx;
				text-align: center;
				border-radius: 8rpx;
				background-color: #C84739;
			}
			image {
				width: 28rpx;
				height: 29rpx;
			}
		}
	}
}
</style>
